package cn.sdhuijin.vms.dao;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import cn.sdhuijin.vms.model.Leave;

public interface ILeaveDao extends JpaRepository<Leave, Long> {
	@Query("select l from Leave l where l.person.id=?1 and ?2 between l.startTime and l.endTime")
	public List<Leave> findByPersonIdAndDate(Long personId, Date now);

	public Page<Leave> findByPersonOrganizationIdIn(Collection<Long> orgIds,
			Pageable pageable);

	@Query("select l from Leave l where l.person.master.id=?1 and TO_DAYS(l.date)=TO_DAYS(NOW()) and l.messageId=?2")
	public Leave findByMasterIdAndMessageId(Long masterId, Long messageId);

	@Query("select max(l.messageId) from Leave l where l.person.master.id=?1 and TO_DAYS(l.date)=TO_DAYS(NOW())")
	public Long getLastMessageId(Long masterId);
}
